package io.jft.doll.weidget

import android.content.Context
import android.graphics.Rect
import android.util.AttributeSet
import android.widget.FrameLayout

/**
 * Created by G on 2017/12/20 0020.
 */
class FullScreenLayout : FrameLayout {
    constructor(context: Context?) : super(context)
    constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
    constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr)

    private val rect = Rect()

    init {
        getWindowVisibleDisplayFrame(rect)
    }

    override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
        if (childCount > 0)
            measureChild(getChildAt(0), MeasureSpec.makeMeasureSpec(rect.right - rect.left, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(rect.bottom - rect.top, MeasureSpec.EXACTLY))
        setMeasuredDimension(rect.right - rect.left, rect.bottom - rect.top)
    }
}